﻿
namespace HSS.ComponentModel
{
	#region Using Directives
	using System;
	using System.ComponentModel;
	using System.Globalization;
	#endregion

	#region StringConverter
	/// <summary>
	/// A string Type converter.
	/// </summary>
	public class StringConverter : TypeConverter
	{
		/// <summary>
		/// Determines if this converter can convert the request type from a string.
		/// </summary>
		/// <param name="context">The ITypeDescriptorContext.</param>
		/// <param name="sourceType">The Type to evaluate.</param>
		/// <returns>true if the sourceType is of type string.</returns>
		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
		{
			return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
		}
		/// <summary>
		/// Attempts to convert the provided value to a string.
		/// </summary>
		/// <param name="context">The ITypeDescriptorContext.</param>
		/// <param name="culture">The CultureInfo.</param>
		/// <param name="value">The value to convert.</param>
		/// <returns>The value converted to a string.</returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
		{
			if (value is string)
				return (string)value;
			if (value == null)
				return string.Empty;
			return base.ConvertFrom(context, culture, value);
		}
	}
	#endregion
}